package com.gaotai.wangfei.exam.filter.interceptor;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import com.gaotai.wangfei.exam.filter.config.IBasicInterceptor;
import com.gaotai.wangfei.exam.filter.config.InterceptorChain;

/**
 * 
 * <p>
 * Description: [字符拦截器]
 * </p>
 * 
 * @author <a href="mailto: wangfei@gaotai.cn">王飞</a>
 * @version $Revision$
 */
public class EncodeInterceptor implements IBasicInterceptor
{

	@Override
	public void destroy()
	{
		// TODO Auto-generated method stub
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, InterceptorChain chain) throws IOException,
		ServletException
	{
		System.out.println("start--Encode--");
		HttpServletRequest httpReq = (HttpServletRequest) request;
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		request.setAttribute("encodeResult", "【EncodeInterceptor已为您自动将编码格式转换为utf-8】");
		chain.doFilter(httpReq, response, chain);
		System.out.println("end--Encode--");
	}

	@Override
	public void init(String interceptorConfig) throws ServletException
	{
		// TODO Auto-generated method stub
	}

}
